home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / OS2 / DIKUMUD.ZIP / TRAP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-30  |  7.0 KB  |  313 lines

  1. /*
  2.   SillyMUD Distribution V1.1b             (c) 1993 SillyMUD Developement
  3.  
  4.   See license.doc for distribution terms.   SillyMUD is based on DIKUMUD
  5. */
  6.  
  7. #include <stdio.h>
  8.  
  9. #include "protos.h"
  10.  
  11. extern struct char_data *character_list;
  12. struct room_data *real_roomp(int);
  13. extern int TrapDir[];
  14.  
  15. void NailThisSucker( struct char_data *ch);
  16.  
  17. void do_settrap( struct char_data *ch, char *arg, int cmd)
  18. {
  19.  
  20.   /* parse for directions */
  21.  
  22. /* trap that affects all directions is an AE trap */
  23.  
  24.   /* parse for type       */
  25.   /* parse for level      */
  26.  
  27. }
  28.  
  29. int CheckForMoveTrap(struct char_data *ch, int dir)
  30. {
  31.   struct obj_data *i;
  32.  
  33.   for (i = real_roomp(ch->in_room)->contents; i; i = i->next_content) {
  34.     if ((ITEM_TYPE(i) == ITEM_TRAP) && 
  35.     (IS_SET(GET_TRAP_EFF(i),TRAP_EFF_MOVE)) &&
  36.     (GET_TRAP_CHARGES(i) > 0))
  37.         if (IS_SET(GET_TRAP_EFF(i), TrapDir[dir])) 
  38.        return(TriggerTrap(ch, i));
  39.   }
  40.   return(FALSE);
  41. }
  42.  
  43. int CheckForInsideTrap(struct char_data *ch, struct obj_data *i)
  44. {
  45.   struct obj_data *t;
  46.  
  47.   for (t = i->contains; t; t = t->next_content) {
  48.     if ((ITEM_TYPE(t) == ITEM_TRAP) && 
  49.     (IS_SET(GET_TRAP_EFF(t),TRAP_EFF_OBJECT)) &&
  50.     (GET_TRAP_CHARGES(t) > 0)) {
  51.        return(TriggerTrap(ch, t));  
  52.      }
  53.   }
  54.   return(FALSE);
  55. }
  56.  
  57. int CheckForAnyTrap(struct char_data *ch, struct obj_data *i)
  58. {
  59.     if ((ITEM_TYPE(i) == ITEM_TRAP) && 
  60.     (GET_TRAP_CHARGES(i) > 0))
  61.        return(TriggerTrap(ch, i));
  62.  
  63.   return(FALSE);
  64. }
  65.  
  66.  
  67.  
  68. int CheckForGetTrap(struct char_data *ch, struct obj_data *i)
  69. {
  70.     if ((ITEM_TYPE(i) == ITEM_TRAP) && 
  71.     (IS_SET(GET_TRAP_EFF(i),TRAP_EFF_OBJECT)) &&
  72.     (GET_TRAP_CHARGES(i) > 0)) {
  73.        return(TriggerTrap(ch, i));  
  74.      }
  75.     return(FALSE);
  76. }
  77.  
  78.  
  79.  
  80. int TriggerTrap( struct char_data *ch, struct obj_data *i)
  81. {
  82.   int adj, fireperc, roll;
  83.   struct char_data *v;
  84.  
  85.   extern struct dex_app_type dex_app[];
  86.  
  87.   if (ITEM_TYPE(i) == ITEM_TRAP) {
  88.     if (i->obj_flags.value[TRAP_CHARGES]) {
  89.     adj = GET_TRAP_LEV(i) - GetMaxLevel(ch);
  90.     adj -= dex_app[GET_DEX(ch)].reaction * 5;
  91.     fireperc = 95 + adj;
  92.     roll = number(1,100);
  93.     if (roll < fireperc) {   /* trap is sprung */
  94.     act("You hear a strange noise...", TRUE, ch, 0, 0, TO_ROOM);
  95.     act("You hear a strange noise...", TRUE, ch, 0, 0, TO_CHAR);
  96.       GET_TRAP_CHARGES(i) -= 1;
  97.       if (IS_SET(GET_TRAP_EFF(i),TRAP_EFF_ROOM)) {
  98.         for (v = real_roomp(ch->in_room)->people;v;v = v->next_in_room) {
  99.           FindTrapDamage(v,i);
  100.         }        
  101.       } else {
  102.         FindTrapDamage(ch,i);
  103.       }
  104.     return(TRUE);
  105.        }
  106.      }
  107.   }
  108.   return(FALSE);
  109. }
  110.  
  111. void FindTrapDamage( struct char_data *v, struct obj_data *i)
  112. {
  113. /*
  114.    trap types < 0 are special
  115. */
  116.  
  117.   if (GET_TRAP_DAM_TYPE(i) >= 0) {
  118.     TrapDamage(v,GET_TRAP_DAM_TYPE(i),3*GET_TRAP_LEV(i),i);
  119.   } else {
  120.      TrapDamage(v, GET_TRAP_DAM_TYPE(i), 0,i);
  121.   }
  122.  
  123. }
  124.  
  125. void TrapDamage(struct char_data *v, int damtype, int amnt, struct obj_data *t)
  126. {
  127.   char buf[132];
  128.  
  129.   amnt = SkipImmortals(v, amnt);
  130.   if (amnt == -1) {
  131.     return;
  132.   }
  133.  
  134.   if (IS_AFFECTED(v, AFF_SANCTUARY))
  135.               amnt = MAX((int)(amnt/2), 0);  /* Max 1/2 damage when sanct'd */
  136.         
  137.    amnt = PreProcDam(v, damtype, amnt);
  138.  
  139.    if (saves_spell(v, SAVING_PETRI))
  140.      amnt = MAX((int)(amnt/2),0);
  141.  
  142.    DamageStuff(v, damtype, amnt);
  143.  
  144.    amnt=MAX(amnt,0);
  145.  
  146.    GET_HIT(v)-=amnt;
  147.  
  148.    update_pos(v);
  149.  
  150.    TrapDam(v, damtype, amnt, t);
  151.  
  152.    InformMess(v);
  153.    if (GET_POS(v) == POSITION_DEAD) {
  154.      if (!IS_NPC(v)) {
  155.        if (real_roomp(v->in_room)->name)
  156.      sprintf(buf, "%s killed by a trap at %s",
  157.          GET_NAME(v),
  158.          real_roomp(v->in_room)->name);
  159.        log(buf);
  160.      }
  161.      
  162.      die(v);
  163.    }
  164.  
  165. void TrapDam(struct char_data *v, int damtype, int amnt, struct obj_data *t)
  166. {
  167.  
  168.   char desc[20];
  169.   char buf[132];
  170.  
  171.   /* easier than dealing with message(ug) */
  172.   switch(damtype) {
  173.   case TRAP_DAM_PIERCE:
  174.     strcpy(desc,"pierced");
  175.     break;
  176.   case TRAP_DAM_SLASH:
  177.     strcpy(desc,"sliced");
  178.     break;
  179.   case TRAP_DAM_BLUNT:
  180.     strcpy(desc,"pounded");
  181.     break;
  182.   case TRAP_DAM_FIRE:
  183.     strcpy(desc,"seared");
  184.     break;
  185.   case TRAP_DAM_COLD:
  186.     strcpy(desc, "frozen");
  187.     break;
  188.   case TRAP_DAM_ACID:
  189.     strcpy(desc, "corroded");
  190.     break;
  191.   case TRAP_DAM_ENERGY:
  192.     strcpy(desc, "blasted");
  193.     break;
  194.   case TRAP_DAM_SLEEP:
  195.     strcpy(desc, "knocked out");
  196.     break;
  197.   case TRAP_DAM_TELEPORT:
  198.     strcpy(desc, "transported");
  199.     break;
  200.   default:
  201.     strcpy(desc, "blown away");
  202.     break;
  203.   }
  204.    
  205.   if ((damtype != TRAP_DAM_TELEPORT)   &&
  206.       (damtype != TRAP_DAM_SLEEP)) {
  207.       if (amnt > 0) {
  208.     sprintf(buf, "$n is %s by $p!", desc);
  209.     act(buf,TRUE,v,t,0,TO_ROOM);
  210.     sprintf(buf, "You are %s by $p!", desc);
  211.     act(buf,TRUE,v,t,0,TO_CHAR);
  212.       } else {
  213.     sprintf(buf, "$n is almost %s by $p!", desc);
  214.     act(buf,TRUE,v,t,0,TO_ROOM);
  215.     sprintf(buf, "You are almost %s by $p!", desc);
  216.     act(buf,TRUE,v,t,0,TO_CHAR);
  217.       }
  218.   }
  219.  
  220.   if (damtype == TRAP_DAM_TELEPORT) {
  221.     TrapTeleport(v);
  222.   } else if (damtype == TRAP_DAM_SLEEP) {
  223.     TrapSleep(v);
  224.   }
  225.  
  226. }
  227.  
  228.  
  229. void TrapTeleport(struct char_data *v) 
  230. {
  231.   int to_room;
  232.   extern int top_of_world;      /* ref to the top element of world */
  233.   
  234.   if (saves_spell(v,SAVING_SPELL)) {
  235.     send_to_char("You feel strange, but the effect fades.\n\r",v);
  236.     return;
  237.   } 
  238.  
  239.   do {
  240.     to_room = number(0, top_of_world);
  241.   } while (IS_SET(real_roomp(to_room)->room_flags, PRIVATE));
  242.   
  243.   act("$n slowly fade out of existence.", FALSE, v,0,0,TO_ROOM);
  244.   char_from_room(v);
  245.   char_to_room(v, to_room);
  246.   act("$n slowly fade in to existence.", FALSE, v,0,0,TO_ROOM);
  247.   
  248.   do_look(v, "", 0);
  249.   
  250.   if (IS_SET(real_roomp(to_room)->room_flags, DEATH) && 
  251.       GetMaxLevel(v) < LOW_IMMORTAL) {
  252.     NailThisSucker(v);
  253.   }
  254. }
  255.  
  256. void TrapSleep(struct char_data *v)
  257. {
  258.   
  259.   struct affected_type af;
  260.   
  261.   if ( !saves_spell(v, SAVING_SPELL) )  {
  262.     af.type      = SPELL_SLEEP;
  263.     af.duration  = 12;
  264.     af.modifier  = 0;
  265.     af.location  = APPLY_NONE;
  266.     af.bitvector = AFF_SLEEP;
  267.     affect_join(v, &af, FALSE, FALSE);
  268.     
  269.     if (GET_POS(v)>POSITION_SLEEPING)    {
  270.       act("You feel very sleepy ..... zzzzzz",FALSE,v,0,0,TO_CHAR);
  271.       act("$n goes to sleep.",TRUE,v,0,0,TO_ROOM);
  272.       GET_POS(v)=POSITION_SLEEPING;
  273.     }
  274.   } else {
  275.     send_to_char("You feel sleepy,but you recover\n\r",v);
  276.   }
  277.   
  278. }
  279.  
  280.  
  281. void InformMess( struct char_data *v)
  282. {
  283.   
  284.   switch (GET_POS(v)) {
  285.   case POSITION_MORTALLYW:
  286.     act("$n is mortally wounded, and will die soon, if not aided.", 
  287.     TRUE, v, 0, 0, TO_ROOM);
  288.     act("You are mortally wounded, and will die soon, if not aided.", 
  289.     FALSE, v, 0, 0, TO_CHAR);
  290.     break;
  291.   case POSITION_INCAP:
  292.     act("$n is incapacitated and will slowly die, if not aided.", 
  293.     TRUE, v, 0, 0, TO_ROOM);
  294.     act("You are incapacitated and you will slowly die, if not aided.", 
  295.     FALSE, v, 0, 0, TO_CHAR);
  296.     break;
  297.   case POSITION_STUNNED:
  298.     act("$n is stunned, but will probably regain consciousness.", 
  299.     TRUE, v, 0, 0, TO_ROOM);
  300.     act("You're stunned, but you will probably regain consciousness.", 
  301.     FALSE, v, 0, 0, TO_CHAR);
  302.     break;
  303.   case POSITION_DEAD:
  304.     act("$n is dead! R.I.P.", TRUE, v, 0, 0, TO_ROOM);
  305.     act("You are dead!  Sorry...", FALSE, v, 0, 0, TO_CHAR);
  306.     break;
  307.   default:  /* >= POSITION SLEEPING */
  308.     break;
  309.   }
  310. }
  311.  
  312.